package com.bjpowernode.crm.workbench.web.controller;

import com.bjpowernode.crm.commons.contants.Contants;
import com.bjpowernode.crm.commons.domain.ReturnObject;
import com.bjpowernode.crm.settings.domain.User;
import com.bjpowernode.crm.workbench.domain.Activity;
import com.bjpowernode.crm.workbench.service.ActivityService;
import com.bjpowernode.crm.workbench.service.ClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ClueConvertController {

    @Autowired
    private ActivityService activityService;

    @Autowired
    private ClueService clueService;

    @RequestMapping(value = "/workbench/clue/queryActivityOfClueByName.do")
    @ResponseBody
    public Object queryActivityOfClueByName(String clueId,String activityName){
        List<Activity> activityList = activityService.queryActivityOfClueByName(clueId,activityName);
        return activityList;
    }

    @RequestMapping(value = "/workbench/clue/covertClue.do")
    @ResponseBody
    public Object covertClue(String clueId,String isCreateTransaction,String amountOfMoney,
                             String tradeName,String expectedClosingDate,String stage,
                             String activityId,HttpSession session){
        ReturnObject returnObject = new ReturnObject();
        User user = (User)session.getAttribute(Contants.SESSION_USER);

        Map<String,Object> map = new HashMap<>();

        map.put(Contants.SESSION_USER,user);
        map.put("clueId",clueId);
        map.put("isCreateTransaction",isCreateTransaction);
        map.put("amountOfMoney",amountOfMoney);
        map.put("tradeName",tradeName);
        map.put("expectedClosingDate",expectedClosingDate);
        map.put("stage",stage);
        map.put("activityId",activityId);

        boolean flag = clueService.doConvertClue(map);

        if(flag == true){
            returnObject.setCode(Contants.RETURN_OBJECT_CODE_SUCCESS);
        }else{
            returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
            returnObject.setMessage("系统繁忙,请稍后再试");
        }

        return returnObject;
    }
}
